package com.har.modules.web.controller;

import com.har.common.exception.RRException;
import com.har.common.utils.R;
import com.har.modules.web.entity.ApplyEntity;
import com.har.modules.web.entity.CommonEntity;
import com.har.modules.web.service.BaseProducService;
import com.har.modules.web.service.LoanService;
import com.har.modules.web.service.RegiserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;

/**
 * 贷款
 *
 * @author maorui
 *
 */
@Slf4j
@RestController
@RequestMapping("/loan")
public class LoanController {


    @Autowired
    private RegiserService regiserService;

    @Autowired
    private LoanService loanService;

    @Autowired
    private BaseProducService baseProducService;

    /**
     *
     *   贷款详细信息
     * @param id
     * @return
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        CommonEntity commonEntity=loanService.selectById(id);
        if (null==commonEntity) {
            throw new RRException("查询出错");
        }
        return R.ok().put("data", commonEntity);
    }

    /**
     *    贷款页面申请
     * @param applyEntity
     * @return
     */
    @RequestMapping("/save")
    public R save(@RequestBody ApplyEntity applyEntity,HttpServletRequest request) throws RRException, ParseException {

        applyEntity.setProductTypeName("贷款");
        regiserService.save(applyEntity,request);
        return R.ok();
    }

    /**
     *  wechat端贷款列表
     *
     * @return
     */
    @RequestMapping("/wechat/list")
    public R queryList(){
        return R.ok().put("data",baseProducService.queryLoanList());
    }
}
